<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_cal.tpl'}-->
    <title>会员列表</title>
</head>
<body>

<div class="container">

    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" class="form-inline" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>会员名：<input type="text" id="custID" class="form-control input-sm w120"  name="custID" /></td>
                                <td>会员号：<input type="text" id="pcustID" class="form-control input-sm w120"  name="pcustID" /></td>
                                <td colspan="4">
                                    &nbsp;
                                    <input type="button" value="查询" class="btn btn-primary" onclick="customer.search();" />&nbsp;&nbsp;
                                    <input type="button" value="重置" class="btn btn-warning" onclick="customer.reset();" />
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
            <table id="flex" style="display:none"></table>
        </div>

</div>
<!--导入 开始-->
<div id="import" style="display: none;">
    <form id="upload_form" name="upload_form" method="post" enctype="multipart/form-data" action="" target="hide_frame">
        <div style="color:#00F">待导入EXCEL文件<BR>第一行为字段TITLE行，第二行开始数据行<BR>第一列为手机号，第二列为会员姓名</div>
        <br>
        <span style="display: inline-block;">
            <input size="130" type="file" id="search_file" name="search_file" style="width:300px">
        </span>
        <input type="button" name="into_sub" id="into_sub" class="btn btn-primary" value="导入">
        <br/>
        <div id="importMsg" style="line-height: 30px;"></div>
        <iframe id="hide_frame" name="hide_frame" style="display: none;"></iframe>
    </form>
</div>
<div id="importUpdateRights" style="display: none;">
    <form id="upload_form_UpdateRights" name="upload_form_UpdateRights" method="post" enctype="multipart/form-data" action="" target="hide_frame">
        <div style="color:#00F">待导入EXCEL文件<BR>第一行为字段TITLE行，第二行开始数据行<BR>第一列为手机号，第二列为多杯权益，第三列为请客权益，第四列为撒娇权益<BR>0代表无权益，1代表有权益，不填写值，代表字段不更新</div>
        <br>
        <span style="display: inline-block;">
            <input size="130" type="file" id="search_file_UpdateRights" name="search_file_UpdateRights" style="width:300px">
        </span>
        <input type="button" name="into_sub_UpdateRights" id="into_sub_UpdateRights" class="btn btn-primary" value="导入">
        <br/>
        <div id="importUpdateRightsMsg" style="line-height: 30px;"></div>
        <iframe id="hide_frameUpdateRights" name="hide_frameUpdateRights" style="display: none;"></iframe>
    </form>
</div>
<!--导入 结束-->
<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/customer/customerTea.ajax?operFlg=1",
        dataType: "json",
        colModel : [
            {display: "会员号", name : "pcustID",align: "center", width : 80, sortable : true},
            {display: "会员名", width : 110},
            {display: "微信OpenID", width : 200},
            {display: "多杯权益", align: "center" , width : 80},
            {display: "请客权益", align: "center" , width : 60},
            {display: "撒娇权益", align: "center" , width : 60},
            {display: "创建时间", align: "center" , width : 140},
            {display: "创建人", align: "center" , width : 100}
        ],
        buttons : [
            {name: "导入会员", bclass: "add", onpress : "customer.import"},
            {name: "导入权益", bclass: "add", onpress : "customer.importUpdateRights"}
        ],
        sortname: "pcustID",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        autoload: true,
        onSubmit: function() {
            var dt = $("#search_form").serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });
    var customer = {
        pcustID:'',

        //搜索会员
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        //重置
        reset: function() {
            document.getElementById('search_form').reset();
            this.search();
        },

        timeClear: function() {
            $('#startDate').val('');
            $('#endDate').val('');
        },

        //批量导入发短信
        import:function(){
            $("#upload_form").attr("action","/quanliadmin/app/customer/customerTea.pscript?operFlg=2");
            E.popup.open({
                id: 'import',
                title: '批量导入会员（Mcake & Tea）',
                css: 'width: 500px;'
            });
        },
        //add by allen.qiang 20150527 批量更新会员权益
        importUpdateRights:function(){
            $("#upload_form_UpdateRights").attr("action","/quanliadmin/app/customer/customerTea.pscript?operFlg=3");
            E.popup.open({
                id: 'importUpdateRights',
                title: '批量更新会员权益',
                css: 'width: 500px;'
            });
        },
        //add by allen.qiang 20150527 批量更新会员权益
        importMsg : function (msg, flg){
            if(flg == 0){
                $("#importMsg").css("color","red");
            }else{
                $("#importMsg").css("color","green");
                //更新 input file
                var input_html = $("#search_file").clone();
                $("#search_file").remove();
                $("#searchForm").prepend(input_html);
                msg = "导入成功";
            }
            $("#importMsg").html(msg);
        },
        //信息提示
        importUpdateRightsMsg : function (msg, flg){
            if(flg == 0){
                $("#importUpdateRightsMsg").css("color","red");
            }else{
                $("#importUpdateRightsMsg").css("color","green");
                //更新 input file
                var input_html = $("#search_file_UpdateRights").clone();
                $("#search_file_UpdateRights").remove();
                $("#searchForm").prepend(input_html);
                msg = "导入成功";
            }
            $("#importUpdateRightsMsg").html(msg);
        },
        load: function() {
            $("#flex").flexReload();
        }
    };

    $('#startDate').datepicker();
    $('#endDate').datepicker();
    //导入执行
    $(document).on('click','#into_sub',function(){
        var filename = $('#search_file').val();
        if(filename == ''){
            customer.importMsg('请选择上传文件',0);
            return false;
        }

        var basename = filename.split(".");
        if(basename[basename.length-1].toLowerCase() != 'xlsx'){
            customer.importMsg('文件类型错误，请选择xlsx文件',0);
            return false;
        }

        $("#importMsg").css("color","black");
        $("#importMsg").text("正在导入，请稍后...");

        $("#upload_form").submit();

    });

    //add by allen.qiang 20150527 批量更新会员权益
    $(document).on('click','#into_sub_UpdateRights',function(){
        var filename = $('#search_file_UpdateRights').val();
        if(filename == ''){
            customer.importUpdateRightsMsg('请选择上传文件',0);
            return false;
        }

        var basename = filename.split(".");
        if(basename[basename.length-1].toLowerCase() != 'xlsx'){
            customer.importUpdateRightsMsg('文件类型错误，请选择xlsx文件',0);
            return false;
        }

        $("#importUpdateRightsMsg").css("color","black");
        $("#importUpdateRightsMsg").text("正在导入，请稍后...");

        $("#upload_form_UpdateRights").submit();

    });

</script>

</body>
</html>